package cn.whitecao.gateway;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.factory.AbstractNameValueGatewayFilterFactory;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;


/**
 * @author ：腼腆的老黄.
 * @date ：Created in 2019-10-16 11:35
 */
@Slf4j
@Component
public class PreLogGatewayFilterFactory extends AbstractNameValueGatewayFilterFactory {
    @Override
    public GatewayFilter apply(NameValueConfig config) {

        return new GatewayFilter() {
            @Override
            public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
                log.info("请求进来了 url={}  .......",exchange.getRequest().getURI());
                ServerHttpRequest httpRequest = exchange.getRequest().mutate().build();
                ServerWebExchange webExchange = exchange.mutate().request(httpRequest).build();
                return chain.filter(webExchange);
            }
        };
    }


}
